package tongwentongshu.com.app.activity;

import android.graphics.Bitmap;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.OnClick;
import tongwentongshu.com.app.App;
import tongwentongshu.com.app.R;
import tongwentongshu.com.app.bean.AppItem;
import tongwentongshu.com.app.bean.PersonalBean;
import tongwentongshu.com.app.bean.SignBean;
import tongwentongshu.com.app.contract.CallBackColonyContract;
import tongwentongshu.com.app.contract.PersonalCenterContract;
import tongwentongshu.com.app.db.Cache;
import tongwentongshu.com.app.dialog.AlertUtils;

/**
 * Created by XiongBin on 2017/7/10.
 */

public class SettingActivity extends BaseActivity implements PersonalCenterContract.View {
    @BindView(R.id.ll_read_people)
    RecyclerView mRecyclerView;
    private PersonalCenterAdapter adapter;

    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_setting;
    }

    @Override
    protected int getTitleId() {
        return R.string.setting;
    }

    @Override
    protected void initView() {
//        App.getApplication().addMallActivity(this);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
                if (classes[position] != null)
                    startActivity(classes[position]);
            }
        });
        adapter = new PersonalCenterAdapter();
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {

    }

    Class[] classes = {PersonalInformationActivity.class, RebuildPasswordActivity.class, FeedbackActivity.class};
    String[] itemList = {"个人资料", "重设密码", "意见反馈"};

    @Override
    public void onSuccess(PersonalBean per) {

    }

    @Override
    public void onSignSuccess(SignBean per) {

    }

    @Override
    public void setHeadImage(Bitmap bmp, String url) {

    }

    @Override
    public void onError() {

    }

    @Override
    public void onHeadSuccess(String msg) {

    }

    public class PersonalCenterAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

        public PersonalCenterAdapter() {
            super(R.layout.view_setting, Arrays.asList(itemList));
        }

        @Override
        protected void convert(BaseViewHolder helper, String item) {
            helper.setText(R.id.tv_name, item);
            if (helper.getPosition() < item.length() + 2)
                helper.getView(R.id.v_line).setVisibility(View.VISIBLE);
            else
                helper.getView(R.id.v_line).setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.rel_login_out})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rel_login_out:
                AlertUtils.showAgainShare(mContext, "是否确认退出？", "确定", "取消", 2, new CallBackColonyContract.OnDiyClick() {
                    @Override
                    public void left() {
                        Cache.Logout(mContext);
                    }

                    @Override
                    public void right() {

                    }
                });

                break;
        }
    }
}
